package edu.unr.cater.npap.share.domain;

import java.util.Arrays;
import java.util.List;

import javax.persistence.ManyToOne;
import javax.persistence.Query;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class ProjectIssues {

    @ManyToOne
    private Project idproject;

    private String projectissues;
    
    public static List<ProjectIssues> findAllProjectIssueses(Integer idProject) {
//        return entityManager().createQuery("SELECT o FROM ProjectIssues o", ProjectIssues.class).getResultList();
        List<Project> idprojects = Arrays.asList(Project.findProject(idProject));
        Query query=entityManager().createQuery("SELECT o FROM ProjectIssues o WHERE o.idproject in (:idprojects)", ProjectIssues.class);
    	query.setParameter("idprojects", idprojects);
        return query.getResultList();
    }
    
   
    
    public static List<ProjectIssues> findProjectIssuesEntries(int firstResult, int maxResults,Integer idProject) {
//        return entityManager().createQuery("SELECT o FROM ProjectIssues o", ProjectIssues.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
        List<Project> idprojects = Arrays.asList(Project.findProject(idProject));
    	Query query=entityManager().createQuery("SELECT o FROM ProjectIssues o WHERE o.idproject in (:idprojects)", ProjectIssues.class).setFirstResult(firstResult).setMaxResults(maxResults);
    	query.setParameter("idprojects", idprojects);
        return query.getResultList();
    }
    
    
    
}
